<layout name='Layout/layout_page' />
	
	<ol class="breadcrumb">
		<li><a href="<{:U('Node/index')}>"><{:L('_menu_node')}></a></li>
      	<li class="active"><{:L('_public_list')}></li>
    </ol>


    <div class="row">
    	<div class="col-md-4 model-item">
    		<h2>Application</h2>
			<select name="group" id="group" class="form-control" SIZE="20">
				<volist name="node" id="vo">
				<option value="<{$vo.id}>"><{$vo.title}>(<{$vo.name}>)</option>
				</volist>
			</select>
			<p>
				<button class="btn btn-info btn-sm" onclick="addNode( '<{:U('Node/add',array('level'=>1,'pid'=>0))}>' , 'group' ,'Add application')"><{:L('_public_add')}></button>
				<button class="btn btn-info btn-sm" onclick="editNode( '<{:U('Node/edit')}>' , 'group' , 'Edit application')"><{:L('_public_edit')}></button>
				<button class="btn btn-info btn-sm" onclick="delNode(1)"><{:L('_public_del')}></button>
			</p>
    	</div>

    	<div class="col-md-4 model-item">
    		<h2>Model</h2>
			<select name="model" id="model" class="form-control" SIZE="20"></select>
			<p>
				<button class="btn btn-info btn-sm" onclick="addNode( '<{:U('Node/add',array('level'=>2))}>' , 'model' ,'Add model')"><{:L('_public_add')}></button>
				<button class="btn btn-info btn-sm" onclick="editNode( '<{:U('Node/edit')}>' , 'model' , 'Edit model')"><{:L('_public_edit')}></button>
				<button class="btn btn-info btn-sm" onclick="delNode(2)"><{:L('_public_del')}></button>
			</p>
    	</div>

    	<div class="col-md-4 model-item">
    		<h2>Action</h2>
			<select name="action" id="action" class="form-control" SIZE="20"></select>
			<p>
				<button class="btn btn-info btn-sm" onclick="addNode( '<{:U('Node/add',array('level'=>3))}>' , 'action' ,'Add action')"><{:L('_public_add')}></button>
				<button class="btn btn-info btn-sm" onclick="editNode( '<{:U('Node/edit')}>' , 'action' , 'Edit action')"><{:L('_public_edit')}></button>
				<button class="btn btn-info btn-sm" onclick="delNode(3)"><{:L('_public_del')}></button>
			</p>
    	</div>
    </div>

<script type="text/javascript">
$(function(){
	$("#group").change(function(){
		var v = $(this).val();
		$.get("index.php?m=Admin&c=Node&a=getChild&pid="+v+"&temp="+new Date().getTime(),function(response){
			$("#model").html(response);	 
		});
		$("#action").html('');
	})

	$("#model").change(function(){
		var v = $(this).val();
		$.get("index.php?m=Admin&c=Node&a=getChild&pid="+v+"&temp="+new Date().getTime(),function(response){
			$("#action").html(response);	 
		});
	})
})

function addNode(url , domid , title){

	if (domid=='model'){
		v= $("#group option:selected").val();
		if (v==undefined) {
			alert("Please select a higher level group");
			return false;
		}else{
			url = url + "&pid=" + v;
		}
	}

	if (domid=='action'){
		v= $("#model option:selected").val();
		if (v==undefined) {
			alert("Please select the superior model");
			return false;
		}else{
			url = url + "&pid=" + v;
		}
	}

	art.dialog.data('domid', domid);
	art.dialog.open(url,{
	lock:true,
	title:title,
	width:800,
	height:400,
	});
}

function editNode(url , domid , title){

	if (domid=='group') {
		name = 'application';
		selOpt = $("#group option:selected");	
	}else if(domid=='model'){
		name = 'model';
		selOpt = $("#model option:selected");
	}else if(domid=='action'){
		name = 'action';
		selOpt = $("#action option:selected");
	}

	v = selOpt.val();
	if(v==undefined){
		alert("Please select the "+name+" you want to edit");
		return false;
	}else{
		url = url + "&id=" + v;
	}

	art.dialog.data('domid', domid);
	art.dialog.open(url,{
	lock:true,
	title:title,
	width:800,
	height:400,
	});
}

function delNode(level){
	if (level==1) {
		name = 'application';
		selOpt = $("#group option:selected");	
	}else if(level==2){
		name = 'model';
		selOpt = $("#model option:selected");
	}else if(level==3){
		name = 'action';
		selOpt = $("#action option:selected");
	}

	v = selOpt.val();
	if(v==undefined){
		alert("Please select the "+name+" you want to delete");
		return false;
	}

	$.get("index.php?m=Admin&c=Node&a=del&level="+level+"&nodeID="+v+"&temp="+new Date().getTime(),function(response){
		if (response==1){
			selOpt.remove();
		}else{
			alert(response);
		} 
	});
 	
}
</script>

<input type="hidden" id="menu_action" value="sys" />
